﻿@using GoodMan.Infrastructure.Entities.Entity;
@{
    Layout = "/Views/Shared/_Main.cshtml";
    User user = ViewBag.User;
}
@section head{
    <link rel="Stylesheet" type="text/css" href="/Content/css/bootstrap-datetimepicker.min.css" />
}
<br />
<div class="row-fluid">
    <div class="span3">
        <div class="border-gray bg-gray">
            <ul class="nav nav-list">
                <li class="nav-header">用户管理</li>
                <!--active-->
                <li class=""><a href="/usercenter/index">管理首页</a></li>
                <li class=""><a href="/usercenter/order">我的订单</a></li>
                <li class="active"><a href="/usercenter/info">个人资料</a></li>
                <li class=""><a href="/usercenter/mypwd">修改密码</a></li>
            </ul>
        </div>
    </div>
    <div class="span9 border-gray">
        <ul class="breadcrumb">
            <li><a href="user-center.html">管理首页</a> <span class="divider">/</span></li>
            <li class="active">个人资料</li>
        </ul>
        @if (ViewBag.Success != null)
        {
            if (ViewBag.Success == "修改成功")
            { 
                <span class="span11 alert alert-success">@ViewBag.Success</span>
            }
            else
            { 
                <span class="span11 alert alert-error">@ViewBag.Success</span>
            }
        }
        <br />
        <div class="">
            <form id="infoform" action="/usercenter/info" method="post" class="form-horizontal">
            <input type="hidden" id="photo" name="photo" />
            <div class="control-group">
                <label class="control-label">
                    登录名</label>
                <div class="controls">
                    <label>
                        @user.UserName</label>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    我的头像</label>
                <div class="controls">
                    <img alt="user" style="width: 100px; height: 100px;" 
                     id="mainphoto" src="@user.Photo" /><br />
                    <div id="swfupload-control">
                        <div>
                            <input type="button" id="btnsltphoto" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="nickname">
                    昵称 (*)</label>
                <div class="controls">
                    <input type="text" name="nickname" value="@user.NickName" placeholder="昵称" />
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="name-real">
                    真实姓名 (*)</label>
                <div class="controls">
                    <input type="text" name="realname" value="@user.RealName" placeholder="真实姓名" />
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    性别</label>
                <div class="controls">
                    <select name="gender">
                        @if (user.Gender == GoodMan.Infrastructure.Entities.Enum.Gender.Male)
                        { 
                            <option value="1" selected="selected">男</option>
                            <option>女</option>
                        }
                        else
                        { 
                            <option value="1">男</option>
                            <option selected="selected">女</option>
                        }
                    </select>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="email">
                    生日 (*)</label>
                <div id="datetimepicker" class="input-append span3">
                    <input id="txtBirthday" value="@user.Birthday.ToString("yyyy-MM-dd")" data-format="yyyy-MM-dd" type="text" name="Birthday" class="{required:true,dateISO:true}" />
                    <span class="add-on"><i class="icon-calendar" data-time-icon="icon-time" data-date-icon="icon-calendar">
                    </i></span>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="email">
                    QQ (*)</label>
                <div class="controls">
                    <input type="text" class="span4 {required:true, number:true}" value="@user.QQ" id="txtQQ" name="QQ" placeholder="请输入您的QQ号" />
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    联系电话 (*)</label>
                <div class="controls">
                    <input type="text" value="@user.Phone" class="span4 {required:true,number:true,minlength:11,maxlength:11}" id="txtPhone" name="Phone" placeholder="请输入您的联系电话" />
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    所在楼栋</label>
                <div class="controls">
                    <select name="FloorId" id="sltFloorId">
                        @{
                            List<Dormitory> dormitories = ViewBag.FloorList;
                            if (dormitories != null)
                            {
                                foreach (var item in dormitories)
                                {
                                    if (user.FloorId == item.Id)
                                    {
                            <option selected="selected" value="@item.Id">@item.Name</option>
                                    }
                                    else
                                    {
                            <option value="@item.Id">@item.Name</option>
                                    }
                                }
                            }
                        }
                    </select>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    寝室号 (*)</label>
                <div class="controls">
                    <input type="text" value="@user.Dormitory" class="span4 {required:true}" id="txtDormitory" name="Dormitory"
                        placeholder="请输入您的寝室号" />
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">
                    身份证号</label>
                <div class="controls">
                    <input type="text" value="@user.IdCardNo" class="span4 {number:true}" id="txtIdCardNo" name="IdCardNo" placeholder="请输入您的身份证号" />
                </div>
            </div>
            <div class="control-group">
                <div class="controls">
                    <br />
                    <button type="submit" class="btn btn-danger">
                        <i class="icon-ok icon-white"></i>&nbsp;修改资料
                    </button>
                </div>
            </div>
            </form>
            <!--#表单-->
        </div>
        <!--#购物车preview-->
    </div>
</div>
@section tail{
    <script type="text/javascript" src="/Scripts/jquery.validate.js"></script>
    <script type="text/javascript" src="/Scripts/jquery.metadata.js"></script>
    <script type="text/javascript" src="/Scripts/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="/scripts/plug.js"></script>
    <script type="text/javascript" src="/scripts/swfupload/swfupload.js"></script>
    <script type="text/javascript" src="/scripts/swfupload/jquery.swfupload.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#datetimepicker').datetimepicker({
                pickTime: false
            });
            $('#infoform').validate({
                errorClass: "help-inline",
                errorElement: "span",
                highlight: function (element, errorClass, validClass) {
                    $(element).parents('.control-group').addClass('error');
                },
                unhighlight: function (element, errorClass, validClass) {
                    $(element).parents('.control-group').removeClass('error');
                }
            });
        });
        $('#swfupload-control').swfupload({
            upload_url: "/UserCenter/SWFPrepareUpload",
            file_size_limit: "7 MB",
            file_types: "*.jpg;*.png",
            file_types_description: "Web Image Files",
            file_upload_limit: 0,
            flash_url: "/scripts/swfupload/swfupload.swf",
            button_image_url: '/scripts/swfupload/updatePhotoBtn.png',
            button_width: 86,
            button_height: 31,
            button_placeholder: $('#btnsltphoto')[0],
            button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE
        })
                .bind('fileQueued', function (event, file) {
                    $(this).swfupload('startUpload');
                })
                .bind('uploadStart', function (event) {
                    $('#mainphoto').attr('src', '/content/img/loading_big.gif');
                })
                .bind('fileQueueError', function (event, file, errorCode, message) {
                    alert(message);
                    $('#mainphoto').attr('src', photo);
                    //$('#log').append('<li>File queue error - ' + message + '</li>');
                })
                .bind('uploadComplete', function (event, file) {
                    $(this).swfupload('startUpload');
                })
                .bind('uploadSuccess', function (event, file, serverData) {
                    var path = eval('(' + serverData + ')').path;
                    $('#mainphoto').attr('src', path);
                    $('#photo').val(path);
                });
    </script>
}